import {createStore} from "redux";
//组件中的共享数据
const cart = [];
//设置reducer
function reducer(state=cart,action){
	switch(action.type){
		case "加入购物车":state.push(action.payload);return state;break;
		// case "数量加":state[action.payload].num++;return state;break;
		case "数量加1":state.cart[action.payload].num++;return state;break;
		case "数量减1":if(state.cart[action.payload].num >0){
			state.cart[action.payload].num--;
		};
		return state;break;
		default:return state;
	}
}
//创建store
var store = createStore(reducer);
export default store;
